import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getDataByService } from '/@/api/sys/base';
import { getCustomerByPage } from '/@/api/plm/customer/customer';
import {getDictListByType} from "/@/api/sys/bizCode";
import {getDictTypes} from "/@/api/sys/dictType";
import {selectDictByType} from "/@/api/sys/dict";

export const columns: BasicColumn[] = [
  {
    title: '客户头像',
    dataIndex: 'profilePicture',
    width: 140,
    slots: { customRender: 'customerImg' },
  },
  {
    title: '客户ID',
    dataIndex: 'customerId',
  },
  {
    title: '客户姓名',
    dataIndex: 'customerName',
  },
  {
    title: '性别',
    dataIndex: 'gender',
  },
  {
    title: '手机号码',
    dataIndex: 'contactNumber',
  },
  {
    title: '固定电话',
    dataIndex: 'landlineNumber',
  },
  {
    title: '联系地址',
    dataIndex: 'address',
  },
  {
    title: '出生日期',
    dataIndex: 'birthDate',
  },
  {
    title: '所属行业',
    dataIndex: 'industry',
  },
  {
    title: '业务类型',
    dataIndex: 'businessType',
  },
  {
    title: '客户状态',
    dataIndex: 'customerStatus',
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'customerName',
    label: '顾客名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'customerStatus',
    component: 'ApiSelect',
    label: '顾客状态',
    componentProps: {
      api: selectDictByType,
      params: {
        dictType: 'customerState',
      },
      labelField: 'dictLabel',
      valueField: 'dictValue',
      showSearch: true,
      optionFilterProp: 'label',
    },
    colProps: { span: 6 },
  },
  {
    field: '[startTime, endTime]',
    label: '时间范围',
    component: 'RangePicker',
    componentProps: {
      style: { width: '100%' },
      format: 'YYYY-MM-DD HH:mm:ss',
      placeholder: ['开始时间', '结束时间'],
      showTime: { format: 'HH:mm:ss' },
    },
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '顾客ID',
    field: 'customerId',
    component: 'Input',
    show: false,
  },
  {
    label: '顾客头像',
    field: 'profilePicture',
    component: 'Input',
    slot: 'profilePicture',
    show: true,
    required: true,
  },
  {
    label: '顾客姓名',
    field: 'customerName',
    component: 'Input',
    show: true,
    required: true,
  },
  {
    field: 'gender',
    component: 'RadioGroup',
    label: '性别',
    componentProps: {
      options: [
        {
          label: 'Female',
          value: 'Female',
        },
        {
          label: 'Male',
          value: 'Male',
        },
      ],
      onChange: (e: any) => {
        console.log('变化值:' + e);
      },
    },
    required: true,
  },
  {
    label: '手机号码',
    field: 'contactNumber',
    component: 'Input',
    show: true,
    rules: [
      {
        required: true,
        // @ts-ignore
        validator: async (rule, value) => {
          const reg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
          if (!reg.test(value)) {
            /* eslint-disable-next-line */
            return Promise.reject("请输入正确的手机号码");
          }
          return Promise.resolve();
        },
        trigger: 'change',
      },
    ],
  },
  {
    label: '固定电话',
    field: 'landlineNumber',
    component: 'Input',
    show: true,
    rules: [
      {
        required: true,
        // @ts-ignore
        validator: async (rule, value) => {
          const reg = /^0\d{2,3}-[1-9]\d{6,7}$/;
          if (!reg.test(value)) {
            /* eslint-disable-next-line */
            return Promise.reject("请输入正确的固定电话");
          }
          return Promise.resolve();
        },
        trigger: 'change',
      },
    ],
  },
  {
    label: '联系地址',
    field: 'address',
    component: 'Input',
    show: true,
  },
  {
    label: '出生日期',
    field: 'birthDate',
    component: 'DatePicker',
    show: true,
  },
  {
    field: 'productType',
    component: 'ApiSelect',
    label: '所属行业',
    componentProps: {
      api: getDataByService,
      params: {
        serviceName: 'io.agilefast.modules.plm.service.impl.PlmIndustryServiceImpl',
        prefix: 'plm',
        labelName: 'industryName',
        valueName: 'industryId',
      },
      labelField: 'label',
      valueField: 'Value',
      showSearch: true,
      optionFilterProp: 'label',
    },
    required: true,
  },
  {
    label: '业务类型',
    field: 'businessType',
    component: 'Input',
    show: true,
  },
  {
    field: 'customerStatus',
    component: 'RadioGroup',
    label: '顾客状态',
    componentProps: {
      options: [
        {
          label: 'Active',
          value: 'Active',
        },
        {
          label: 'Inactive',
          value: 'Inactive',
        },
        {
          label: 'Lost',
          value: 'Lost',
        },
      ],
      onChange: (e: any) => {
        console.log('变化值:' + e);
      },
    },
    required: true,
  },
];
